package com.xuwei.service.impl;

import com.xuwei.mapper.UserMapper;
import com.xuwei.pojo.User;
import com.xuwei.pojo.Users;
import com.xuwei.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String name, String password) {
        User user = userMapper.login(name, password);
        if(user!=null){
            return user;
        }else{
            return null;
        }

    }

    @Override
    public List<Users> findUserAll() {
        List<Users> usersList = userMapper.findUserAll();
        if (usersList!=null){
            return usersList;
        }
        return null;
    }

    @Override
    public void addUser(Users users) {
       userMapper.addUser(users);
    }

    @Override
    public void updateUser(Users users) {
       userMapper.updateUser(users);
    }

    @Override
    public Users findUserById(int id) {
        Users users = userMapper.findUserById(id);
        return users;
    }

    @Override
    public void delById(int id) {
        userMapper.delById(id);
    }

    @Override
    public List<Users> search(String name) {
      return userMapper.search(name);
    }
}
